home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / FIND.CPP < prev    next >
Text File  |  1997-05-06  |  748b  |  34 lines

  1.  #include <vector>
  2.  #include <algorithm>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    typedef vector<int>::iterator iterator;
  9.    int d1[10] = {0,1,2,2,3,4,2,2,6,7};
  10.    //
  11.    // Set up a vector.
  12.    //
  13.    vector<int> v1(d1+0, d1+10);
  14.    //
  15.    // Try find.
  16.    //
  17.    iterator it1 = find(v1.begin(), v1.end(), 3);
  18.    //
  19.    // Try find_if.
  20.    //
  21.    iterator it2 = find_if(v1.begin(), v1.end(), bind1st(equal_to<int>(), 3));
  22.    //
  23.    // Try both adjacent_find variants.
  24.    //
  25.    iterator it3 = adjacent_find(v1.begin(), v1.end());
  26.    iterator it4 = adjacent_find(v1.begin(), v1.end(), equal_to<int>());
  27.    //
  28.    // Output results.
  29.    //
  30.    cout << *it1 << " " << *it2 << " " << *it3 << " " << *it4 << endl;
  31.  
  32.    return 0;
  33.  }
  34.